import Form,{ Field } from './rc-field-form';
import React from 'react';
import ReactDOM from 'react-dom';
let uniqueValidator = (rule, value, callback, form) => {
    return new Promise((resolve,reject)=>{
    setTimeout(()=>{
        if(value === 'zhufeng'){
        resolve(`用户名已经被占用`);
        }else{
        resolve('');
        }
    },3000);
    });
}
ReactDOM.render(
  <React.StrictMode>
      <Form
        initialValues={{username: '',password: ''}}
        onFinish={(values)=>{
            console.log(values)
        }}
        onFinishFailed={(errorInfo)=>{
            console.log('失败:',errorInfo);
        }}
      >
          <Field name="username" rules={[{ required: true },{ min: 3 },{validator:uniqueValidator}]}>
              <input placeholder="用户名"/>
          </Field>
          <Field name="password" rules={[{ required: true }]}>
              <input placeholder="密码"/>
          </Field>
          <button>
              提交
          </button>

      </Form>
  </React.StrictMode>,
  document.getElementById('root')
);
